package webapp.mvc.finders;

import com.zoowii.jpa_utils.extension.ExtendFinder;
import com.zoowii.jpa_utils.extension.Paginator;
import webapp.mvc.enums.IntBooleans;
import webapp.mvc.models.ProductEntity;

import java.util.List;

public class ProductFinder extends ExtendFinder<String, ProductEntity> {
    public ProductFinder(Class<?> kCls, Class<?> mCls) {
        super(kCls, mCls);
    }
    public List<ProductEntity> getProductsOfShop(String shopId, Paginator paginator) {
        paginator = paginator.eq("deleted", IntBooleans.FALSE)
                .eq("shopId", shopId);
        return this.findByPaginator(paginator);
    }

    public ProductEntity findByName(String name) {
        return this.where().eq("deleted", IntBooleans.FALSE)
                .eq("name", name).first();
    }
}
